package com.xianggu.designMode.combination.demo01;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author chengjy
 * @date 2025/3/15
 */
public class Menu extends MenuComponent{

    private List<MenuComponent> menuComponents = new ArrayList<>();

    public Menu(String name, int level) {
        this.name = name;
        this.level = level;
    }

    @Override
    public void add(MenuComponent menuComponent) {
        menuComponents.add(menuComponent);
    }

    @Override
    public void addAll(MenuComponent... menuComponent) {
        menuComponents.addAll(Arrays.asList(menuComponent));
    }

    @Override
    public void remove(MenuComponent menuComponent) {
        menuComponents.remove(menuComponent);
    }

    @Override
    public MenuComponent getChild(int index) {
        return menuComponents.get(index);
    }

    @Override
    public String getName() {
        return super.getName();
    }

    @Override
    public void print() {
        for (int i = level; i > 0; i--) {
            System.out.print(" ");
        }
        System.out.println( "-" + getName());
        for (MenuComponent menuComponent : menuComponents) {
            for (int i = level; i > 0; i--) {
                System.out.print(" ");
            }
            menuComponent.print();
        }
    }
}
